package j2EE.io;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Created with Intel IDEA.
 * 将BytesArrayOutputStream 改为 ServletOutputStream 子类的Utility 类
 *
 *
 * @Auther: gjt
 * @Date: 2024/9/1 14:22
 */
public class CacheOutputStream extends ServletOutputStream {
    private ByteArrayOutputStream bos;

    public CacheOutputStream (){
        bos = new ByteArrayOutputStream();
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {

    }


    @Override
    public void write(int b) throws IOException {
        bos.write(b);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        bos.write(b, off, len);
    }

    public byte[] toByteArray(){
        return bos.toByteArray();
    }
}
